-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid updating the block gap when it's unchanged #5540
Avoid updating the block gap when it's unchanged #5540
Conversation
Previously, the block gap storage could be updated even when the gap is the same as before. This patch fixes it by only updating the storage when the gap is changed.
Pure tiny refactoring, no logical changes. The benefit of consistent format strings is 10 lines of deletion. The other style changes are added by the rust formatter.
3485cf4
to
f2a260b
Compare
Previously, the block gap state in `BlockchainDb` in unconditionally updated whenever `try_commit_operation` is invoked, even if the state hadn't changed. This commit refines the logic to update the block gap state only when a change occurs, reducing unnecessary writes and improving efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with this part of the codebase. Overall looks good, but I don't know if block gap can be updated in the db from other places.
@davxy can you have a look, please?
meta_keys::BLOCK_GAP, | ||
&(start, end).encode(), | ||
); | ||
if start > end { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the block gap can't be updated externally and returned from self.blockchain.meta.read()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm pretty sure that update_block_gap()
is the only way to update the gap in meta and it's only invoked at the end of try_commit_operation()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
&(start, end).encode(), | ||
); | ||
} | ||
block_gap_updated = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related nit: In below condition number > best_num + One::one()
implies number >One::one()
.
So the second condition can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already addressed by #5343, feel free to ignore
9b28a54
There are basically three commits in this PR. Since all these commits essentially have no logical changes, I packed them into one PR. Review by per-commit is recommended.
BlockchainDb
.